//
//  Contact.m
//  OC6_数组&集合课后作业练习2
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Contact.h"

@implementation Contact

- (id)initWithName:(NSString *)name sex:(NSString *)sex phonenum:(NSString *)phonenum address:(NSString *)address group:(NSString *)group age:(NSInteger)age
{
    self = [super init];
    if (self) {
        [self setName:name];
        [self setSex:sex];
        [self setPhonenum:phonenum];
        [self setAddress:address];
        [self setGroup:group];
        [self setAge:age];
    }
    return self;
}

- (void)info
{
    NSLog(@"%@ %@ %@ %@ %@ %ld", [self name], [self sex], [self phonenum], [self address], [self group], [self age]);
}

- (NSComparisonResult)compareContactByName:(Contact *)contact
{
    return [[contact name] compare:[self name]];
}

- (NSComparisonResult)compareContactByAge:(Contact *)contact
{
    if ([self age] > contact.age) {
        return NSOrderedAscending;
    }
    if (self.age < [contact age]) {
        return NSOrderedDescending;
    }
    else
        return NSOrderedSame;
    
}




@end
